import { Request, Response, NextFunction } from 'express'
import { createUserLikePost, deleteUserLikePost } from './like.service'

export const storeUserLikePost = async (
  req: Request,
  res: Response,
  next: NextFunction
) => {
  const { postId } = req.params
  const { id: userId } = req.user

  try {
    const data = await createUserLikePost(userId, +postId)
    res.send(data)
  } catch (error) {
    next(error)
  }
}

export const destroyUserLikePost = async (
  req: Request,
  res: Response,
  next: NextFunction
) => {
  const { postId } = req.params
  const { id: userId } = req.user

  try {
    const data = await deleteUserLikePost(userId, +postId)
    res.send(data)
  } catch (error) {
    next(error)
  }
}
